package com.jelly.mina.simpleness;

import java.net.InetSocketAddress;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketConnector;

public class MainClient {
	@SuppressWarnings("deprecation")
	public static void main(String[] args) {
		// create TCP/IP connector
		NioSocketConnector connector = new NioSocketConnector();
		DefaultIoFilterChainBuilder chain = connector.getFilterChain();
		chain.addLast("mychain", new ProtocolCodecFilter(new TextLineCodecFactory()));
		connector.setHandler(new SamplMinaClientHandler());
		connector.setConnectTimeout(30);
		ConnectFuture cf = connector.connect(new InetSocketAddress("localhost",1234));
		// Wait for the connection attempt to be finished.
		cf.awaitUninterruptibly(); ;
		cf.getSession().getCloseFuture().awaitUninterruptibly();
		connector.dispose();
	}
}
